home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 19 / madtrb11.zip / WINWRI.PAS < prev    next >
Pascal/Delphi Source File  |  1985-12-17  |  24KB  |  1,230 lines

  1. program window_write;    { for MS include (input,output) }
  2.  
  3. { for MS replace # with chr(...) around the number  below }
  4.  
  5.  
  6. const
  7.   maxfields = 40;     { for now }
  8.   ul_c      = #218;
  9.   ll_c         = #192;
  10.   ur_c         = #191;
  11.   lr_c         = #217;
  12.   v_c          = #179;
  13.   h_c          = #196;
  14.   maxitems     = 10;    { for menugen }
  15.   maxwindows   = 50;
  16.   maxevents    = 50;
  17.   current_attribute = #7;
  18.  
  19.  
  20. type
  21.   lst  = string[80];
  22.  
  23.   lst_p  = ^lst;
  24.  
  25.   dte = record
  26.     year : integer;
  27.     month : integer;
  28.     day : integer;
  29.    end;  { dte }
  30.  
  31.  
  32.    duo = array[0..1] of integer;
  33.    quad = array[0..3] of integer;
  34.    position = duo;
  35.    line_type = quad;
  36.  
  37.  
  38.   time_type = record
  39.     hour : byte;
  40.     minute : byte;
  41.     second : byte;
  42.    end;   { time_type }
  43.  
  44.   field = array[0..1] of lst;  { 1 for label, one for data }
  45.  
  46.  
  47.   input_field_p  = ^input_field_type;
  48.  
  49.   screen_p    = ^screen_type;
  50.  
  51.   window_p    = ^window_type;
  52.   
  53.   task_p      = ^task;
  54.  
  55.   event_p =   ^event_record;
  56.  
  57.  
  58.   task = record
  59.     begin_task: task_p;
  60.     get_info  : event_p;
  61.     other_stuff : task_p;
  62.     put_info  : event_p;
  63.     end_task  : task_p;
  64.    end;
  65.  
  66.  
  67.  
  68.   input_field_type =  record
  69.      location   : position;   { relative to NW corner of window }
  70.      data_area  : field;
  71.      last_field : input_field_p;
  72.      next_field : input_field_p;
  73.     end;   { input_field }
  74.  
  75.  
  76.   screen_type = record
  77.      data_area  : array[0..maxfields] of input_field_type;
  78.      w_p        : window_p;
  79.      end;
  80.  
  81.   screen_type_file = file of screen_type;
  82.  
  83.   
  84.  
  85.   textstring_type = record
  86.      the_text : array[0..1000] of char;
  87.      strpos   : integer;
  88.      len      : integer;
  89.     end;
  90.  
  91.  
  92.  window_type = record
  93.      ulLR     : QUAD;
  94.      job      : integer;
  95.      s_p      : screen_p;
  96.      text     : textstring_type;
  97.     end;      { window_type }
  98.  
  99.  
  100.   setofchar   = set of char;
  101.  
  102.   regpack = record
  103.      ax,bx,cx,dx,bp,di,si,ds,es,flags  : integer;
  104.   end;
  105.  
  106.  
  107.   amount  = array [0..7] of char;
  108.  
  109.  
  110.   event_record = record
  111.        active_window : window_p;
  112.        mouse_down    : boolean;
  113.        mouse_where   : position;
  114.        keypress      : boolean;
  115.        key           : char;
  116.        cursor_where  : position;
  117.        sysreq        : byte;
  118.        end;   { event_record }
  119.  
  120.   event_record_file = file of event_record;
  121.  
  122.  
  123.   system_status_type = record
  124.        active_window : byte;
  125.        drives_on     : byte;  { bit coded..1 on is A:, 2 on is B:, etc }
  126.        time          : time_type;
  127.        date          : dte;
  128.        cursor_where  : position;
  129.        end;     { system_status_type }
  130.  
  131.  
  132.  
  133.   screen_position_pair_type = (char_byte, attr_byte);
  134.  
  135.   imagetype = array[1..25,1..80,char_byte..attr_byte] of char;
  136.  
  137.  
  138.   image_p     = ^imagetype;
  139.  
  140.  
  141.  
  142.  
  143.  
  144. var
  145.   ch , up, down, left, right, retrn, escape, home,
  146.   endd, pgup, pgdn,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10 :  char;
  147.   i                    : integer;
  148.   scp                  : screen_p;   { screen pointer }
  149.   wp                   : array[1..maxwindows] of window_p;   { window pointer }
  150.   wp_index             : integer;
  151.   control_set          : setofchar;
  152.   event                : event_record;
  153.   system_status        : system_status_type;
  154.   counter, max         : integer;
  155.   system_okset         : setofchar;
  156.  
  157.  
  158.   crtmode,page,width   : byte;
  159.   monobuffer           : imagetype absolute $B000:$0000;
  160.   colorbuffer          : imagetype absolute $B800:$0000;
  161.   buffer               : imagetype;
  162.   screen_stack         : array[0..maxwindows] of image_p;
  163.  
  164.  
  165. procedure incr(var i : integer);
  166.  
  167. begin
  168.   i := i + 1;
  169. end;
  170.  
  171.  
  172.  
  173.  
  174. procedure get_screen(var buffer : imagetype);
  175.  
  176. begin
  177.     if crtmode = 7 then buffer := monobuffer else
  178.             buffer := colorbuffer;
  179. end;
  180.  
  181.  
  182.  
  183. procedure put_screen(var buffer : imagetype);
  184.  
  185. begin
  186.     if crtmode = 7 then monobuffer := buffer else
  187.             colorbuffer := buffer;
  188. end;
  189.  
  190.  
  191.  
  192. procedure decr(var i : integer);
  193.  
  194. begin
  195.   i := i - 1;
  196. end;
  197.  
  198.  
  199.  
  200.  
  201.  
  202. procedure init_var;
  203.  
  204.  
  205. begin
  206.   wp_index := 0;
  207.   escape := #27;
  208.   retrn  := #13;
  209.   up     := #9;
  210.   down   := #10;
  211.   left   := #11;
  212.   right  := #12;
  213.   home   := #14;
  214.   endd   := #15;
  215.   pgup   := #16;
  216.   pgdn   := #17;
  217.   f1     := #1;
  218.   f2     := #2;
  219.   f3     := #3;
  220.   f4     := #4;
  221.   f5     := #5;
  222.   f6     := #6;
  223.   f7     := #7;
  224. end;   { procedure init_var }
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233. procedure putchar(x,y : integer; ch : char);
  234. begin
  235.     if crtmode = 7 then monobuffer[y,x,char_byte] := ch else
  236.             colorbuffer[y,x,char_byte] := ch;
  237. end;
  238.  
  239.  
  240.  
  241.  
  242.  
  243. PROCEDURE PUTSTRING(xcoord, ycoord : integer;s :lst);
  244.  
  245. var
  246.   i :integer;
  247.  
  248. begin
  249.   for i := 1 to length(s) do putchar((xcoord + i - 1), ycoord,s[i]);
  250. end;   { PUTSTRING }    
  251.  
  252.  
  253.  
  254.  
  255. PROCEDURE INVERSE;
  256.  { sets current screen attribute (used by PUTSTRING) to inverse status }
  257.  
  258. BEGIN
  259.  
  260.    
  261.    textcolor(black);
  262.    textbackground(white);
  263.  
  264. END;   { inverse }
  265.  
  266.  
  267.  
  268.  
  269.  
  270. PROCEDURE NORMAL;
  271.  { sets the current screen attribute (used by PUTSTRING) to normal status }
  272.  
  273. BEGIN
  274.  
  275.    
  276.    textcolor(white);
  277.    textbackground(black);
  278.  
  279. END;   { normal }
  280.  
  281.  
  282.  
  283. PROCEDURE DRAWBOX(col, line, horiz, vert : integer);
  284.  
  285. VAR
  286.    I                    : INTEGER;
  287.    S                    : LST;
  288.    ul,ur,ll,lr,h,v      : char;
  289.  
  290. BEGIN  { DRAWBOX }
  291.  
  292.    UL := CHR(218); {┌}
  293.    UR := CHR(191); {┐}
  294.    LL := CHR(192); {└}
  295.    LR := CHR(217); {┘ }
  296.    H  := CHR(196); {─ }
  297.    V  := CHR(179); {│ }
  298.  
  299.  
  300.    
  301.    s := '';
  302.    for i := 1 to horiz do s:= concat(s,h);
  303.    
  304.    s := concat(ul,s,ur);
  305.    putstring(col,line,s);
  306.    
  307.    
  308.     { DRAW RIGHT VERTICAL LINE }
  309.    FOR I := 1 TO (VERT + 1) DO
  310.         begin
  311.    
  312.    
  313.           putchar(col,(line + i),v);
  314.           putchar((col + horiz + 1),(line + i),v);
  315.         end;
  316.    
  317.    
  318.     { DRAW BOTTOM LINE }
  319.    
  320.    s := '';
  321.    for i := 1 to horiz do s:= concat(s,h);
  322.    
  323.    s := concat(ll,s,lr);
  324.    putstring(col,(line + vert + 1),s);
  325.  
  326.  
  327. END;   { DRAWBOX }
  328.  
  329.  
  330.  
  331.  
  332.  
  333. procedure put_box(text1, text2:lst);
  334.  
  335. const
  336.    maxlength  = 75;
  337.  
  338. begin
  339.   drawbox(0,20,77,2);
  340.   if (length(text1) > maxlength) then text1 := copy(text1,1,75);
  341.   if (length(text2) > maxlength) then text2 :=  copy(text2,1,75);
  342.   putstring(2,21,text1);
  343.   putstring(2,22,text2);
  344. end;  { put_box }
  345.  
  346.  
  347.  
  348.  
  349.  
  350. PROCEDURE   SET_CURSOR_TYPE  (var start: byte; var  stop : byte);
  351. { use byte type as parameter so number is straight binary }
  352.  
  353. var
  354.   recpack : regpack;
  355.  
  356. begin
  357.  
  358.  with recpack do
  359.   begin
  360.     ax := 1 shl 8;   { set cursor type call }
  361.     cx := start shl 8 + stop;  { start goes into bits 4-0 of CH }
  362.   end;
  363.  
  364.   intr($10,recpack);
  365. end;   { set_cursor_type }
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372. PROCEDURE   CURRENT_VIDEO_STATE
  373.        (var page  : byte;     { parameter is modified }
  374.         var mode  : byte;     { parameter is modified }
  375.         var width : byte);    { parameter is modified }
  376.  
  377. var
  378.   recpack : regpack;
  379.  
  380. begin
  381.   with recpack do ax := 15 shl 8; {  video state request }
  382.   intr($10,recpack);              {  int hex 10 is video services }
  383.   with recpack do
  384.     begin
  385.       mode :=  ax; { actually in AL }
  386.       width := swap(ax);  { AH }
  387.       page  := swap(bx);  { BH }
  388.     end;
  389. end;   { current_video_state }
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399. PROCEDURE RESET_CURSOR;                           { internal to SAFELIB.IMP }
  400.  
  401.  { turns cursor back to underline }
  402.  
  403. VAR
  404.    PAGE,MODE,WIDTH,START,STOP : byte;
  405.  
  406. BEGIN  { reset_cursor }
  407.  
  408. CURRENT_VIDEO_STATE(PAGE,MODE,WIDTH); { find out what kind of monitor this is }
  409.  
  410. IF MODE = 7 THEN BEGIN                { monochrome }
  411.    START := 12;
  412.    STOP := 13;
  413. END
  414. ELSE BEGIN
  415.    START := 7;
  416.    STOP := 7;
  417. END;  (* if *)
  418. SET_CURSOR_TYPE(START,STOP);
  419.  
  420. END;   { reset_cursor }
  421.  
  422. PROCEDURE SET_CURSOR;                           { internal to SAFELIB.IMP }
  423.  
  424.  { turns cursor into large white block }
  425.  
  426. VAR
  427.    PAGE,MODE,WIDTH,START,STOP : byte;
  428.  
  429. BEGIN  { set_cursor }
  430.  
  431. CURRENT_VIDEO_STATE(PAGE,MODE,WIDTH); { find out what kind of monitor this is }
  432. START := 0;                           { cursor_start will be top line }
  433. IF MODE = 7 THEN STOP := 13           { if monochrome, last line is 13 }
  434. ELSE STOP := 7;                       { else color or graphice, last line = 7 }
  435. SET_CURSOR_TYPE(START,STOP);          { set it }
  436.  
  437. END;   { set_cursor }
  438.  
  439.  
  440.  
  441.  
  442. procedure zero_cursor;
  443.  
  444. var
  445.   a,b : byte;
  446.  
  447. begin
  448.   reset_cursor;
  449. end;   { zereo_cursor }
  450.  
  451.  
  452.  
  453.  
  454. function getchar(okset : setofchar; cursoron : boolean): char;
  455.  
  456.  
  457. const
  458.    prefix = #0;   { Turbo's version of chr(0) }
  459.    BELL   = #7;
  460.  
  461.  
  462. var
  463.   ch : char;
  464.   good   : boolean;
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471. function getchar_detail:char;   {does the DOS call }
  472.  
  473.   type
  474.    regpack = record
  475.               ax,bx,cx,dx,bp,si,ds,es,flags: integer;
  476.             end;
  477.  
  478.   var
  479.    recpack : regpack;
  480.  
  481.   begin
  482.      recpack.ax := $07 shl 8;
  483.      { puts the Hex 07 call (KB input) into AH }
  484.      MsDos(recpack);
  485.      getchar_detail := chr(lo(recpack.ax));
  486.      { keystroke is returned in AL -- this seems to read it ok }
  487.  
  488.   end;  { getchar_detail }
  489.  
  490.  
  491. begin
  492.   if (cursoron) then set_cursor;
  493.  
  494.  
  495.   REPEAT
  496.    ch := getchar_detail;
  497.    IF CH = PREFIX THEN BEGIN     { prefixed key }
  498.       ch := getchar_detail; { get next key that is sitting there }
  499.       CASE ORD(CH) OF
  500.          75 : ch := LEFT;
  501.          77 : CH := RIGHT;
  502.          72 : CH := UP;
  503.          80 : CH := DOWN;
  504.          59 : ch := f1;
  505.          60 : ch := f2;
  506.          61 : ch := f3;   {á}
  507.          62 : ch := f4;   { í }
  508.          63 : ch := f5;   { ó }
  509.          64 : ch := #163;    
  510.          65 : ch := #164;
  511.          66 : ch := #165;
  512.          67 : ch := #174;
  513.          68 : ch := #168;   {» }
  514.  
  515.  
  516.          71 : ch := home;
  517.          73 : ch := pgup;
  518.          79 : ch := endd;
  519.          81 : ch := pgdn;
  520.          else CH := CHR(0);
  521.       END;  { case }
  522.    END;  { if }
  523.  
  524.   good := ch in okset;
  525.   if not good then write(bell)
  526.   else if (ord(ch) >= 32) and (cursoron) then write(ch);
  527.  
  528. UNTIL good;
  529.  
  530. getchar := ch;
  531.   if (cursoron) then
  532. reset_cursor;
  533.  
  534. end; { function getchar }
  535.  
  536.  
  537.                                     { PC Specific }
  538.  
  539. {-----------end of SAFELIB procedures --------------------------------------}
  540.  
  541.  
  542. procedure mouses(var m : quad);  { quad is a type, array [0..3] of integer} 
  543.  
  544. const
  545.    mouse_intr = 51;
  546.  
  547. var
  548.   recpack   : regpack;
  549.  
  550. begin
  551. { with recpack do 
  552.      begin
  553.        ax := m[1];
  554.        bx := m[2];
  555.        cx := m[3];
  556.        dx := m[4];
  557.      end;
  558.   Intr(mouse_intr, recpack); 
  559.   with recpack do 
  560.      begin
  561.        m[1] := ax;
  562.        m[2] := bx;
  563.        m[3] := cx;
  564.        m[4] := dx;
  565.      end; }
  566. end; { Mouses}
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575. procedure gettime(var time : time_type);
  576.  
  577. var
  578.   local_time : time_type;
  579.   recpack    : regpack;  
  580.  
  581. begin
  582.   with recpack do
  583.    begin
  584.      ax := $2c shl 8;   { time of day request }
  585.    end;
  586.    msdos(recpack);      { dos call }
  587.  with recpack do
  588.   begin
  589.    local_time.second := dx shr 8;
  590.    local_time.minute := cx mod 256;
  591.    local_time.hour   := cx shr 8;
  592.    with local_time do
  593.     if hour > 12 then hour := hour - 12;
  594.  
  595.   end;
  596.  
  597.    time := local_time;
  598. end;  { gettime }
  599.  
  600.  
  601.  
  602.  
  603. procedure getdate(var local_date :dte);
  604.  
  605. var
  606.   recpack    : regpack;
  607.  
  608. begin
  609.   with recpack do
  610.    begin
  611.      ax := $2a shl 8;   { date request }
  612.    end;
  613.    msdos(recpack);      { dos call }
  614.   with recpack do
  615.   begin
  616.    local_date.year  := cx;
  617.    local_date.day   := dx mod 256;
  618.    local_date.month := dx shr 8;
  619.   end;
  620. end;  { getdate }
  621.  
  622.  
  623.  
  624. procedure draw_window(window_pointer : window_p);
  625.  
  626. var
  627.   x, y : integer;
  628.  
  629. begin
  630.   with Window_pointer^ do
  631. begin
  632.       for y := ullr[1] to ullr[3] do
  633.         for x := ullr[0] to ullr[2] do
  634.             putchar(x,y,' ');
  635.  
  636.      drawbox(ullr[0],ullr[1], (ullr[2] - ullr[0]), (ullr[3] - ullr[1]) );
  637.  
  638.  end;
  639.  end;
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650. procedure get_event(var event : event_record);
  651.  
  652. var
  653.   iq : quad;
  654.  
  655. begin
  656.  
  657. {event.keypress  := KeyPressed;}
  658.  
  659. { intrinisc boolean }
  660.  
  661.  
  662.  
  663. event.key := getchar(system_okset,false);
  664.  
  665. if event.key = f1 then event.sysreq := 5 else    { open window }
  666.   if event.key = f2 then event.sysreq := 6 else
  667.     if event.key = f3 then event.sysreq := 7 else      { cut window }
  668.       if event.key = f5 then event.sysreq := 9;     { move window around }
  669.  
  670. mouses(iq);
  671.  
  672. end;
  673.  
  674.  
  675.  
  676.  
  677. procedure stoptest;
  678.  
  679. var
  680.   ch : char;
  681.  
  682.  
  683. begin
  684.   write(#7);
  685.   ch := getchar([retrn], false);
  686. end;
  687.  
  688.  
  689.  
  690.  
  691.  
  692. procedure write_text(start : integer;var wp : window_p; event : event_record);
  693.  
  694. var
  695.   loc : position;
  696.     strsize : integer;
  697.     counter : integer;
  698.     effrs, effls : integer;
  699.  
  700.  
  701. begin
  702.  
  703.  
  704.   with event do
  705.     begin
  706.      with wp^ do
  707.      begin
  708.       strsize  := text.len;
  709.  
  710.       loc[0] := ullr[0] + 1;
  711.  
  712.       loc[1] := ullr[1] + 1;
  713.  
  714.       counter := start;
  715.  
  716.        repeat
  717.          counter := counter + 1;
  718.             if loc[1] <   ullr[3] then
  719.                 putchar(loc[0],loc[1],text.the_text[counter]);
  720.  
  721.  
  722.          loc[0] := loc[0] + 1;  { x-coord }
  723.          if loc[0] >= ullr[2] then
  724.          begin
  725.            loc[1] := loc[1] + 1;
  726.            loc[0] := ullr[0] + 1;
  727.          end;
  728.  
  729.       until (counter >= strsize) or (loc[1] > ullr[3]);
  730.  
  731.     text.strpos := counter - 1;
  732.  
  733.    end;   { with wp[wp_index]^ }
  734.  
  735. end;  { with event }
  736.  
  737. end;   { write_text }
  738.  
  739.  
  740.  
  741.  
  742.  
  743.  
  744. procedure get_text(columns: integer;var event : event_record);
  745.  
  746.  
  747.  
  748.  
  749.  
  750. var
  751.   okset : setofchar;
  752.   temp_x:integer;
  753.   pos : position;
  754.   temp_buf     : lst;
  755.   debug_lst    : lst;
  756.   ch           : char;
  757.  
  758.  
  759.  
  760.  
  761.  
  762. begin    { get_text }
  763.  
  764.  
  765.  WITH EVENT DO
  766.   BEGIN
  767.    with wp[wp_index]^ do
  768.     begin
  769.  
  770.     if (key in system_okset) and (ord(key) > 31)   { add key to string, print}
  771.        and (cursor_where[1]<=ullr[3]) and (cursor_where[0]<ullr[2])
  772.         then
  773.              if (cursor_where[0] >=  ullr[2]) and (cursor_where[1]<ullr[3])
  774.                 then { wrap }
  775.  
  776.                   begin
  777.                    cursor_where[0] := ullr[0]+1;  {x_coord}
  778.                    incr(cursor_where[1]);
  779.                    incr(text.strpos);
  780.                    text.the_text[text.strpos] := key;
  781.                    putchar(cursor_where[0], cursor_where[1],key);
  782.                    incr(cursor_where[0]);
  783.                    incr(text.strpos);
  784.                   end  {  wrap }
  785.  
  786.              else              { not wrap }
  787.               if (cursor_where[1]<ullr[3]) then
  788.  
  789.                 begin
  790.                   putchar(cursor_where[0], cursor_where[1],key);
  791.  
  792.                   cursor_where[0] := cursor_where[0] + 1;
  793.                   incr(text.strpos);
  794.                   text.the_text[text.strpos] := key;
  795.                 end;
  796.  
  797.  
  798.  
  799.     if (key in [up,down,left,right]) then
  800.       begin
  801.         case ord(key) of
  802.         9 :                     { UP }
  803.            begin
  804.              text.strpos := text.strpos - ((ullr[2]) - (ullr[0]));
  805.              cursor_where[1] := cursor_where[1] - 1;
  806.              if (cursor_where[1] <=  ullr[1]) then { wrap }
  807.                       cursor_where[1] := ullr[3];
  808.  
  809.            end;
  810.  
  811.  
  812.  
  813.          10  : {down}
  814.            begin
  815.              text.strpos := text.strpos + ((ullr[2]) - (ullr[0]));
  816.              cursor_where[1] := cursor_where[1] + 1;
  817.              if (cursor_where[1] >  ullr[3]) then { wrap }
  818.                       cursor_where[1] := ullr[1] + 1;
  819.                      { should handel strpos here someday }
  820.            end;
  821.  
  822.          11  : {left}
  823.            begin
  824.              text.strpos := text.strpos - 1;
  825.              cursor_where[0] := cursor_where[0] - 1;
  826.              if (cursor_where[0] <=  ullr[0]) then { wrap }
  827.                       cursor_where[0] := ullr[2] - 1;
  828.                      { should handel strpos here someday }
  829.            end;
  830.  
  831.  
  832.          12 : {right --ff?}
  833.            begin
  834.              text.strpos := text.strpos + 1;
  835.              cursor_where[0] := cursor_where[0] + 1;
  836.              if (cursor_where[0] >=  ullr[2]) then { wrap }
  837.                       cursor_where[0] := ullr[0] + 1;
  838.            end;
  839.        end;   { case }
  840.       end;    { if key in [up...}
  841.  
  842.      with text do if (strpos > len) then len := strpos;
  843.  
  844.  
  845.   end;   { with wp[event_p]^. }
  846.  
  847.  end;   { with event do }
  848.  
  849. end;  { get_text }
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858. procedure window_manage(var event : event_record);
  859.  
  860. var
  861.   corners : quad;
  862.   columns : integer;
  863.   ch      : char;
  864.   start, stop : byte;
  865.   temp_window: window_type;   { temporary window }
  866.   temp_buf   : imagetype;
  867.   i          : integer;
  868.  
  869.  
  870. begin
  871. if event.sysreq = 5 then    { make window }
  872.  
  873. begin
  874.  wp_index := wp_index + 1;    { overall layer counter }
  875.  
  876.  { save current screen }
  877.  new(screen_stack[wp_index]);
  878.  get_screen(buffer); 
  879.  screen_stack[wp_index]^ := buffer;
  880.  
  881.  { make new window }
  882.  new(wp[wp_index]);
  883.  
  884.  corners[0]  := 40;
  885.  corners[1]  := 12;
  886.  
  887.  gotoxy(corners[0],corners[1]);
  888.  set_cursor;
  889.  
  890.  { establish NW corner of window }
  891. repeat
  892.    ch := getchar([retrn, right, down,left, up,home], false);
  893.    if (ch = left) then
  894.         corners[0] := corners[0] - 1;
  895.  
  896.    if (ch = up) then corners[1] := corners[1] - 1;
  897.    if (ch = right) then
  898.         corners[0] := corners[0] + 1;
  899.  
  900.    if (ch = down) then corners[1] := corners[1] + 1;
  901.    if (ch = home) then
  902.      begin
  903.         corners[0] := corners[0] - 1;
  904.         corners[1] := corners[1] - 1;
  905.      end;
  906.  
  907.    GotoXY(corners[0],corners[1]);
  908.  until ( ch = retrn);
  909.  
  910.  
  911.  corners[2] := corners[0];
  912.  corners[3] := corners[1];
  913.  
  914.  
  915.    { get SE corner from user  -- keep showing box }
  916.  repeat
  917.    ch := getchar([retrn, right, down,home,endd,pgup,pgdn], false);
  918.    if (ch = right) then
  919.         corners[2] := corners[2] + 1;
  920.  
  921.    if (ch = down) then corners[3] := corners[3] + 1;
  922.    if (ch = home) then
  923.      begin
  924.         corners[2] := corners[2] - 1;
  925.         corners[3] := corners[3] - 1;
  926.      end;
  927.  
  928.    if (ch = endd) then
  929.      begin
  930.         corners[2] := corners[2] - 1;
  931.         corners[3] := corners[3] - 1;
  932.      end;
  933.  
  934.    if (ch = pgup) then
  935.      begin
  936.         corners[2] := corners[2] + 1;
  937.         corners[3] := corners[3] - 1;
  938.      end;
  939.  
  940.    if (ch = pgdn) then
  941.      begin
  942.         corners[2] := corners[2] + 1;
  943.         corners[3] := corners[3] + 1;
  944.      end;
  945.  
  946.  
  947.    wp[wp_index]^.ullr := corners;
  948.    draw_window(wp[wp_index]);
  949.  until ( ch = retrn);
  950.  
  951.  
  952.  draw_window(wp[wp_index]);   { will clean inside of box }
  953.  
  954.  wp[wp_index]^.text.strpos := 0;
  955.  wp[wp_index]^.text.len := 1;
  956.  
  957.  
  958.  event.cursor_where[0] := corners[0]+1;
  959.  event.cursor_where[1] := corners[1]+1;
  960.      { set things up for action inside the box }
  961.  
  962.  
  963.  EVENT.Active_Window := wp[wp_index];
  964.  
  965.  reset_cursor;
  966.  
  967.  
  968.  end
  969.     { if sysreq = 5 }
  970.  else if (event.sysreq = 6) then   { zap window }
  971.   begin
  972.    if (wp_index > 1) then 
  973.  
  974.    begin            
  975.      dispose(wp[wp_index]);                { pop window stack }
  976.      if (crtmode = 7) then monobuffer := screen_stack[wp_index]^
  977.          else colorbuffer := screen_stack[wp_index]^;
  978.              { restore previous screen }
  979.      dispose(screen_stack[wp_index]);
  980.      decr(wp_index);
  981.    end
  982.   end  { if sysreq = 6 }
  983.  
  984. else if (event.sysreq = 7) then   { scroll--top window to bottom }
  985.                                   { of stack, everybody moves up one }
  986.  
  987.   begin
  988.     temp_buf           := screen_stack[wp_index]^;
  989.     temp_window        := wp[wp_index]^;
  990.                { save top of stacks }
  991.     for i := (wp_index - 1) downto 1 do
  992.      begin
  993.       screen_stack[i + 1]^ := screen_stack[i]^;
  994.       wp[i + 1]^          := wp[i]^;
  995.      end;
  996.         { pop the stacks }
  997.  
  998.     screen_stack[1]^ := temp_buf;
  999.     wp[1]^          := temp_window;
  1000.  
  1001.     for i := 1 to wp_index do
  1002.      begin
  1003.        draw_window(wp[i]);
  1004.        write_text(1,wp[i],event);
  1005.      end;
  1006.  
  1007.     event.cursor_where[0] := wp[i]^.ullr[0]+1;
  1008.     event.cursor_where[1] := wp[i]^.ullr[1]+1;
  1009.  
  1010.  
  1011.   end   { = 7 }
  1012.  else if (event.sysreq = 8) then    { make window without getting coords }
  1013. begin
  1014.  wp_index := wp_index + 1;    { overall layer counter }
  1015.  
  1016.  { save current screen }
  1017.  new(screen_stack[wp_index]);
  1018.  get_screen(buffer); 
  1019.  screen_stack[wp_index]^ := buffer;
  1020.  
  1021.  { make new window }
  1022.  new(wp[wp_index]);
  1023.  
  1024.  wp[wp_index] := event.active_window;  { get coords that are in event_record }
  1025.  
  1026.  draw_window(wp[wp_index]);   { will clean inside of box }
  1027.  
  1028.  wp[wp_index]^.text.strpos := 0;
  1029.  wp[wp_index]^.text.len := 1;
  1030.  
  1031.  
  1032.  event.cursor_where[0] := corners[0]+1;
  1033.  event.cursor_where[1] := corners[1]+1;
  1034.      { set things up for action inside the box }
  1035.  
  1036.  
  1037.  EVENT.Active_Window := wp[wp_index];
  1038.  
  1039.  
  1040.  reset_cursor;
  1041.  
  1042.  
  1043.  end
  1044.  else if event.sysreq=9 then   { move window around }
  1045.  
  1046.  begin
  1047.   { get keystroke, move frame }
  1048.   repeat
  1049.     with wp[wp_index]^ do begin
  1050.       ch := getchar([retrn, right, down,left, up,home], false);
  1051.       if (ch = left) then 
  1052.            begin
  1053.              decr(ullr[0]); decr(ullr[2]);
  1054.            end;
  1055.    
  1056.       if (ch = up) then 
  1057.            begin
  1058.              decr(ullr[1]); decr(ullr[3]);
  1059.            end;
  1060.  
  1061.       if (ch = right) then
  1062.            begin
  1063.              incr(ullr[0]); incr(ullr[2]);
  1064.            end;
  1065.  
  1066.    
  1067.       if (ch = down) then 
  1068.            begin
  1069.              incr(ullr[1]); incr(ullr[3]);
  1070.            end;
  1071.  
  1072.       draw_window(wp[wp_index]);
  1073.     end   { with wp[wp_index]^ }
  1074.  until (ch=retrn);
  1075.     { now clear screen, redraw whole system }
  1076.     clrscr;
  1077.     
  1078.     for i := 1 to wp_index do
  1079.      begin
  1080.        draw_window(wp[i]);
  1081.        write_text(1,wp[i],event);
  1082.      end;
  1083.  
  1084.     event.cursor_where[0] := wp[i]^.ullr[0]+1;
  1085.     event.cursor_where[1] := wp[i]^.ullr[1]+1;
  1086.  
  1087.  end;
  1088.  
  1089. event.sysreq := 0;
  1090.  
  1091. end; {manage_window...}
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098. procedure manage_system_okset(m_okset : setofchar);
  1099.  
  1100. begin end;
  1101.  
  1102.  
  1103.  
  1104.  
  1105. procedure update_system_rec(sysrec : system_status_type);
  1106.  
  1107.  
  1108. procedure show_status(sysrec : system_status_type);
  1109.  
  1110. const
  1111.   slash = '/';
  1112.   colon = ':';
  1113.  
  1114. var
  1115.   h,m,s,d,y   : string[4];
  1116.   datestr, timestr  : string[12];
  1117.  
  1118.  
  1119. begin
  1120.   with sysrec do
  1121.   begin
  1122.     str(date.day,d);
  1123.     str(date.month,m);
  1124.     str(date.year,y);
  1125.     datestr := m + slash+ d + slash + y;
  1126.     str(time.second:2,s); if s[1]=' ' then s[1] := '0';
  1127.     str(time.minute:2,m); if m[1]=' ' then m[1] := '0';
  1128.     str(time.hour:2,h); if h[1]=' ' then h[1] := '0';
  1129.     timestr := h + colon + m + colon + s ;
  1130.   end;
  1131.   drawbox(1,1,12,2);
  1132.   putstring(2,2,'        ');
  1133.   putstring(2,3,'        ');
  1134.   putstring(2,2,datestr);
  1135.   putstring(2,3,timestr);
  1136.  
  1137. end;
  1138.  
  1139.  
  1140.  
  1141. begin
  1142. with sysrec do
  1143.   begin
  1144.       getdate(sysrec.date);
  1145.       gettime(sysrec.time);
  1146.       show_status(sysrec);
  1147.       gotoxy(cursor_where[0],cursor_where[1]);
  1148.  
  1149.   end;
  1150. end;
  1151.  
  1152.  
  1153.  
  1154.  
  1155.  
  1156.  
  1157. procedure read_init_file;
  1158.  
  1159. var
  1160.  
  1161.   quad_file : file of quad;
  1162.   the_quad  : quad;   { TYPE QUAD is an array[0..3] of integer }
  1163.  
  1164.  
  1165.  
  1166. begin
  1167.   assign(quad_file,'config.dat');
  1168.   reset(quad_file);
  1169.  
  1170.  
  1171.   while not eof(quad_file) do 
  1172.     begin
  1173.       read(quad_file, the_quad);
  1174.       event.sysreq := 8;
  1175.       event.active_window^.ullr := the_quad;
  1176.  
  1177.       window_manage(event);
  1178.     end;
  1179.  
  1180. end;   { read_init_file }
  1181.  
  1182.  
  1183.  
  1184.   
  1185.  
  1186.  
  1187. begin    { winwri }
  1188.   CURRENT_VIDEO_STATE(page,crtmode,width);
  1189.  
  1190.   counter := 0;
  1191.   init_var;
  1192.        if crtmode = 7 then buffer := monobuffer
  1193.               else buffer := colorbuffer;
  1194. { read_init_file; }
  1195.   system_okset := [#1..#254,up,down,left,right,escape,retrn,f1,f2];
  1196.   clrscr;
  1197.  
  1198.  event.sysreq := 0;
  1199.   repeat
  1200.     event.sysreq := 5; { make_window }
  1201.  
  1202.      repeat
  1203.  
  1204.        window_manage(event);
  1205.  
  1206.        system_status.cursor_where := event.cursor_where;
  1207.        update_system_rec(system_status);
  1208.  
  1209.        get_event(event);
  1210.  
  1211.        system_status.cursor_where := event.cursor_where;
  1212.        update_system_rec(system_status);
  1213.  
  1214.        get_text(1,event);
  1215.  
  1216.  
  1217.     until(event.key = escape);
  1218.  
  1219.  
  1220.     manage_system_okset(system_okset);
  1221.     incr(counter); 
  1222.  
  1223. until (counter > 0);  { indicates quit }
  1224.  
  1225.  
  1226.    reset_cursor;
  1227.  
  1228.  
  1229.   end.
  1230.